package com.zxl.app.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.zxl.common.exception.BusinessException;
import com.zxl.common.mapper.SysInformationMapper;
import com.zxl.common.model.pojo.SysInformation;
import com.zxl.common.model.pojo.SysInformationGroup;
import com.zxl.common.model.query.information.InformationQuery;
import com.zxl.common.model.vo.information.InformationDetailVo;
import com.zxl.common.model.vo.information.InformationRecommendVo;
import com.zxl.common.model.vo.information.InformationVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/24
 */
@Service
public class InformationService {
    @Resource
    private SysInformationMapper sysInformationMapper;


    public List<InformationVo> selectInformation(InformationQuery query) {
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        List<InformationVo> list = sysInformationMapper.selectInformation(query);
        return list;
    }


    public InformationDetailVo details(Integer id) {
        InformationDetailVo informationDetailVo = new InformationDetailVo();
        InformationVo informationVo = sysInformationMapper.selectDetails(id);
        if (informationVo == null){
            throw new BusinessException("找不到该新闻");
        }
        List<InformationRecommendVo> informationRecommendVos = sysInformationMapper.recommend(informationVo.getId(), informationVo.getGroupId());
        informationDetailVo.setInformationVo(informationVo);
        informationDetailVo.setInformationRecommendVo(informationRecommendVos);
        return informationDetailVo;
    }


}
